package sc.tool.sqlgen.branchinfo.pfs;

import java.util.Comparator;

public class StringLengthComparator implements Comparator<String> {

    public static final StringLengthComparator ASC_INSTANCE = new StringLengthComparator(true);
    public static final StringLengthComparator DESC_INSTANCE = new StringLengthComparator(false);

    public StringLengthComparator(boolean ascending) {
        super();
        this.ascending = ascending;
    }

    boolean ascending;

    @Override
    public int compare(String o1, String o2) {
        if (ascending) {
            return o1.length() - o2.length();
        } else {
            return o2.length() - o1.length();
        }
    }

}
